package ui.fragment.setting;

import android.content.ContentResolver;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.trek2000.android.enterprise.R;

import java.io.File;
import java.util.ArrayList;

import adapter.custom.gallery.AlbumListAdapter;
import adapter.setting.CompanyLogoAdapter;
import define.MediaType;
import model.Album;
import ui.activity.custom.camera.CustomCamera;
import ui.activity.custom.gallery.CustomGallery;
import utils.Utils;

public class CompanyLogoFragment extends Fragment
        implements View.OnClickListener {

    /**
     * Data section
     */

    /**
     * String section
     */
    public static boolean IS_IN_COMPANY_LOGO_FRAGMENT = false;
    /**
     * View section
     */
    private LinearLayout mLlTakeNew;
    private ListView mLv;
    private TextView mTvTakeNew;

    /**
     * Others section
     */

    /**
     * Listener section
     */

    public static Fragment newInstance() {
        CompanyLogoFragment fragment = new CompanyLogoFragment();
        return fragment;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_take_new:
                // Go to Custom Camera page.
                if (Utils.checkCameraHardware(getActivity())) {
                    // If device support Camera feature,
                    // call Camera activity
                    startActivity(new Intent(getActivity(), CustomCamera.class));
                } else {
                    // If device not support Camera feature,
                    // show Toast message.
                    Toast.makeText(getActivity(),
                            "Current device not support Camera!",
                            Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.ll_album_in_fragment_company_logo:
                // Go to Gallery page
                // call Camera activity
                startActivity(new Intent(getActivity(), CustomGallery.class));
                break;
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        Log.i("", "onCreateView");

        /**
         * Set Orientation for page
         */
        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        View v = getLayoutInflater(savedInstanceState).inflate(
                R.layout.fragment_company_logo, container, false);

        // Initial views
        initialViews(v);
        initialData();

        return v;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();

        Log.i("", "onDestroyView");

        IS_IN_COMPANY_LOGO_FRAGMENT = false;
    }

    @Override
    public void onResume() {
        super.onResume();

        Log.i("", "onResume");
    }

    /**
     * Initialize methods
     */

    private void initialData() {
        /**
         * Set listener
         */
        mLlTakeNew.setOnClickListener(this);

        // Get folder list to shown on page

        // Set adapter for list view
        ArrayList<model.File> mAlAlbums = new ArrayList<>();

        String[] FILE_PATH = new String[] {
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_1)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_1)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_1),
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_2)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_2)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_2),
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_3)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_3)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_3),
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_4)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_4)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_4),
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_5)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_5)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_5),
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_6)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_6)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_6),
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_7)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_7)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_7),
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_8)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_8)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_8),
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_9)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_9)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_9),
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_10)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_10)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_10),
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_11)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_11)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_11),
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_12)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_12)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_12),
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_13)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_13)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_13),
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_14)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_14)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_14),
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_15)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_15)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_15),
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_16)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_16)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_16),
                ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                        + getResources().getResourcePackageName(R.drawable.iv_17)
                        + '/' + getResources().getResourceTypeName(R.drawable.iv_17)
                        + '/' + getResources().getResourceEntryName(R.drawable.iv_17),
        };


        for (String item : FILE_PATH) {
            model.File file = new model.File(
                    getActivity(), "", item, false);

            // Add item into Array list Photos
            mAlAlbums.add(file);
        }

        // Set adapter
        mLv.setAdapter(new CompanyLogoAdapter(
                getActivity(),
                R.layout.simple_list_item_in_album_list,
                mAlAlbums));
    }

    private void initialViews(View v) {
        mLv = (ListView) v.findViewById(R.id.lv_in_fragment_custom_gallery);
        mLlTakeNew = (LinearLayout) v.findViewById(R.id.ll_take_new);
        mTvTakeNew = (TextView) v.findViewById(R.id.tv_take_new);
    }

    /**
     * The others methods
     */
}

